import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';
import { render } from '/@/utils/common/renderUtils';
const { t } = useI18n('asset.inventoryPlan.fields');
const { t: common } = useI18n('common');
const { t: asset } = useI18n('asset.assetInfo.fields');
const inventoryField = {
  name: t('name'),
  executionMethod: t('executionMethod'),
  executionDate: t('executionDate'),
  checkState: t('check_state'),
  inventoryState: t('inventory_state'),
  inventoryWay: t('inventory_way'),
  notes: t('notes'),
  inventoryPerson: t('inventory_person'),
  createTime: t('createTime'),
  inventory_type: t('inventory_type'),
};
//列表数据
export const columns: BasicColumn[] = [
  {
    title: inventoryField.name,
    align: 'center',
    dataIndex: 'name',
    fixed: 'left',
  },
  //盘点方式
  {
    title: inventoryField.executionMethod,
    align: 'center',
    dataIndex: 'executionMethod',
    customRender: ({ text, record }: { text: any; record: any }) => {
      const colors: any = { 1: 'green', 2: 'blue' };
      if (record.enabled === '0') {
        colors[1] = undefined;
      }
      if (text) {
        return render.renderDict(text, 'execution_method', true, colors);
      }
    },
  },
  {
    title: inventoryField.executionDate,
    align: 'center',
    dataIndex: 'executionMethod',
    customRender: ({ text }) => {
      if (text) {
        return render.renderDict(text, 'execution_date');
      }
    },
  },

  {
    title: inventoryField.inventoryWay,
    align: 'center',
    dataIndex: 'inventoryWay',
    customRender: ({ text }) => {
      if (text) {
        return render.renderDict(text, 'inventoryWay', true);
      }
    },
  },
  {
    title: inventoryField.inventoryPerson,
    align: 'center',
    dataIndex: 'inventoryPerson',
  },
  {
    title: inventoryField.createTime,
    align: 'center',
    dataIndex: 'createTime',
  },
  {
    title: inventoryField.notes,
    align: 'center',
    dataIndex: 'notes',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: inventoryField.name,
    field: 'name',
    component: 'Input',
    componentProps: {
      type: 'like',
    },
  },
  {
    label: inventoryField.createTime,
    field: 'createTime',
    component: 'RangePicker',
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: inventoryField.name,
    field: 'name',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true, message: common('inputText') + inventoryField.name }];
    },
  },
  {
    label: inventoryField.executionMethod,
    field: 'executionMethod',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'execution_method',
      showChooseOption: false,
    },
    dynamicRules: () => {
      return [{ required: true, message: common('chooseText') + '执行方式' }];
    },
  },
  {
    label: inventoryField.executionDate,
    field: 'executionDate',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'execution_date',
      showChooseOption: false,
    },
    ifShow({ values }) {
      return values.executionMethod == '1';
    },
    dynamicRules: () => {
      return [{ required: true, message: common('chooseText') + '执行时间' }];
    },
  },
  {
    label: inventoryField.inventoryWay,
    field: 'inventoryWay',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'inventoryWay',
      showChooseOption: false,
    },
    dynamicRules: () => {
      return [{ required: true, message: common('inputText') + inventoryField.inventoryWay }];
    },
  },
  {
    label: '资产位置',
    field: 'positionName',
    component: 'JTreeSelect',
    componentProps: {
      dict: 'asset_position,position_name,id',
      pidField: 'pid',
      pidValue: '0',
      hasChildField: 'has_child',
    },
    ifShow({ values }) {
      return values.inventoryWay == '4';
    },
    // ifShow({ values }) {
    //   return values.inventoryWay !== '2';
    // },
  },
  {
    label: inventoryField.inventoryPerson,
    field: 'inventoryPerson',
    component: 'JSelectUserByDept',
    componentProps: {
      labelKey: 'realname',
    },
    dynamicRules: () => {
      return [{ required: true, message: common('inputText') + inventoryField.inventoryPerson }];
    },
    // ifShow({ values }) {
    //   return values.inventoryWay == '4';
    // },
  },
  {
    label: asset('cartegory'),
    field: 'categoryName',
    component: 'JTreeSelect',
    componentProps: { dict: 'asset_category,category_name,id', pidField: 'pid', pidValue: '0', hasChildField: 'has_child' },
    ifShow({ values }) {
      return values.inventoryWay == '2';
    },
  },
  {
    label: asset('useState'),
    field: 'useState',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'useState',
      showChooseOption: false,
    },
    ifShow({ values }) {
      return values.inventoryWay == '4' || values.inventoryWay == '3';
    },
  },
  {
    label: t('useDepartment'),
    field: 'departmentId',
    component: 'JSelectDept',
    ifShow({ values }) {
      return values.inventoryWay == '3';
    },
  },
  {
    label: t('user'),
    field: 'user',
    component: 'JSelectUserByDept',
    componentProps: {
      labelKey: 'realname',
    },
    ifShow({ values }) {
      return values.inventoryWay == '4';
    },
  },
  {
    label: asset('description'),
    field: 'notes',
    component: 'Input',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];
//资产信息数据
export const assetColumns: BasicColumn[] = [
  {
    title: asset('name'),
    dataIndex: 'name',
  },
  {
    title: asset('cartegory'),
    dataIndex: 'cartegory_dictText',
  },

  {
    title: asset('code'),
    dataIndex: 'code',
  },
  {
    title: asset('position'),
    align: 'center',
    dataIndex: 'position_dictText',
  },
  {
    title: asset('useState'),
    dataIndex: 'useState',
    customRender: ({ text }) => {
      return render.renderDict(text, 'useState');
    },
  },
  {
    title: '使用部门',
    dataIndex: 'custodyDepartment_dictText',
  },
];
/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
